package com.jiu345.api.controller;

import com.jiu345.api.pojo.Banner;
import com.jiu345.api.pojo.Cart;
import com.jiu345.api.pojo.vo.CartVo;
import com.jiu345.api.service.IBannerService;
import com.jiu345.api.service.ICartService;
import com.jiu345.core.page.PageQuery;
import com.jiu345.core.page.TableDataInfo;
import com.jiu345.users.pojo.Address;
import com.jiu345.users.pojo.bo.CartBo;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * package:GoodsCateController
 * @author MrLei QQ:235921049
 * @date 2024-07-19
 * desc:购物车
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/user/cart")
public class CartController extends BaseController {
    private final ICartService cartService;
    /*根据用户ID查询购物车列表-分页*/
    @GetMapping("/list")
    public TableDataInfo<CartVo> selectByUserId(PageQuery pageQuery){
        return cartService.selectByUserIdPageList(pageQuery);
    }

    /*添加购物车*/
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody Cart bo){

        return toAjax(cartService.insertByBo(bo));
    }
    /**
     * 删除购物车商品
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(cartService.deleteSkuGoodsByIds(List.of(ids), true));
    }

    /*修改购物车商品数量*/
    @PutMapping("/updateNumber")
    public R<Void> updateSkuNumber(@Validated(EditGroup.class) @RequestBody CartBo bo) {
        return toAjax(cartService.updateNumber(bo));
    }

    /*购物车全选/取消*/
    @PutMapping("/isCheckedAll")
    public R<Void> isCheckedAll(@Validated(EditGroup.class) @RequestBody CartBo bo) {
        return toAjax(cartService.isCheckedAll(bo));
    }

}
